package com.ATMgui;

import com.util.Util;

import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.ArrayList;

public class ATM extends JFrame implements ActionListener {
    private ArrayList<Users> usersList = new ArrayList();
    private CardLayout cardLayout = new CardLayout();
    private Login login = new Login(this);
    private Menu menu = new Menu(this);
    private GetMoney getMoney = new GetMoney(this);
    private SaveMoney saveMoney = new SaveMoney(this);
    private FindMoney findMoney = new FindMoney(this);
    private Zhuanzhang zhuanzhang = new Zhuanzhang(this);
    private AlterPassword alterPassword = new AlterPassword(this);
    private Image bgimg = Util.getImage("/image/background.jpg");
    private int num;//下标

    public SaveMoney getSaveMoney() {
        return saveMoney;
    }

    public void setSaveMoney(SaveMoney saveMoney) {
        this.saveMoney = saveMoney;
    }

    public FindMoney getFindMoney() {
        return findMoney;
    }

    public void setFindMoney(FindMoney findMoney) {
        this.findMoney = findMoney;
    }

    public ArrayList<Users> getUsersList() {
        return usersList;
    }

    public void setUsersList(ArrayList<Users> usersList) {
        this.usersList = usersList;
    }


    private void init() {
        FileUtil.readObject("d:/1.dat");
    }

    @Override
    public void actionPerformed(ActionEvent e) {

    }

    public ATM() {
        init();
        this.setContentPane(new JPanel() {
            @Override
            protected void paintComponent(Graphics g) {
                super.paintComponent(g);
                g.drawImage(bgimg, 0, 0, 800, 600, this);
            }
        });
        this.setLayout(cardLayout);
        //登陆按钮
        this.add("登陆", login);
        this.add("菜单", menu);
        this.add("取钱", getMoney);
        this.add("存钱", saveMoney);
        this.add("查询", findMoney);
        this.add("改密码", alterPassword);
        this.add("转账", zhuanzhang);

        this.setSize(800, 600);
        this.setTitle("ATM");
        this.setLocationRelativeTo(null);
        this.setDefaultCloseOperation(EXIT_ON_CLOSE);
        this.setVisible(true);
    }

    public static void main(String[] args) {
        new ATM();
    }

    public void switchPanel(String name) {
        cardLayout.show(this.getContentPane(), name);
    }


    public int getNum() {
        return num;
    }

    public void setNum(int num) {
        this.num = num;
    }

    public AlterPassword getAlterPassword() {
        return alterPassword;
    }
}
